﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Security.Cryptography;
using System.Text;
using System.Web;
using System.Xml;

namespace SystmicFunction.Public.CharacterService
{
    /// <summary>
    ///     字符处理器
    /// </summary>
    public static class Processor
    {
        #region MD5加密

        private const string DefaultFormat = "{0}-DEFSHARE-DEFAULT";

        /// <summary>
        ///     MD5加密：默认加密格式
        /// </summary>
        /// <param name="keyWord">加密文字</param>
        /// <returns>加密字符</returns>
        public static string Encryption(string keyWord)
        {
            var inbuf = Encoding.UTF8.GetBytes(string.Format(DefaultFormat, keyWord));
            MD5 md5 = MD5.Create();
            var outbuf = md5.ComputeHash(inbuf);
            return BitConverter.ToString(outbuf).Replace("-", "");
        }

        #endregion

        #region HTML编码 ULR编码

        /// <summary>
        ///     Html编码
        /// </summary>
        /// <param name="str"></param>
        /// <returns></returns>
        public static String HtmlEncode(String str)
        {
            return HttpUtility.HtmlEncode(str);
        }

        /// <summary>
        ///     Html解码
        /// </summary>
        /// <param name="str"></param>
        /// <returns></returns>
        public static String HtmlDecode(String str)
        {
            return HttpUtility.HtmlDecode(str);
        }

        /// <summary>
        ///     URL编码
        /// </summary>
        /// <param name="str"></param>
        /// <returns></returns>
        public static String UrlEncode(String str)
        {
            return HttpUtility.UrlEncode(str);
        }

        /// <summary>
        ///     URL解码
        /// </summary>
        /// <param name="str"></param>
        /// <returns></returns>
        public static String UrlDecode(String str)
        {
            return HttpUtility.UrlDecode(str);
        }

        #endregion

        #region JSON处理

        /*********
         * Json.Net
         * 访问：http://json.codeplex.com/
         * 
         * 
         */

        public static void ToJson<TEntity>(TEntity t) where TEntity : class
        {

        }



        #endregion

        #region XML处理

        /// <summary>
        ///  TODO:XML处理
        /// </summary>
        /// <param name="postStr"></param>
        public static void Xml(String postStr)
        {
            XmlDocument doc = new XmlDocument();
            doc.LoadXml(postStr);

            XmlElement rootElement = doc.DocumentElement;
            XmlNode MsgType = rootElement.SelectSingleNode("MsgType");

            //MsgType.InnerText;
        }

        #endregion

        #region 格式化字符



        #endregion


    }
}
